//
//  ShareBottomView.m
//  Cat
//
//  Created by lushitong on 2019/1/1.
//  Copyright © 2019年 lushitong. All rights reserved.
//

#import "ShareBottomView.h"

@interface ShareBottomView()

@property (nonatomic, strong) UIButton *leftButton;
@property (nonatomic, strong) UIButton *rightButton;

@property (nonatomic, strong) UIView *leftView;
@property (nonatomic, strong) UIImageView *leftImageView;
@property (nonatomic, strong) UILabel *leftLabel;

@property (nonatomic, strong) UIView *rightView;
@property (nonatomic, strong) UIImageView *rightImageView;
@property (nonatomic, strong) UILabel *rightLabel;

@property (nonatomic, copy) void(^clickQQBlock)(void);
@property (nonatomic, copy) void(^clickWechatBlock)(void);

@end

@implementation ShareBottomView

- (void)clickShareQQButton:(void (^)(void))qqBlock andWechatButton:(void (^)(void))weChatBlock {
	self.clickQQBlock = qqBlock;
	self.clickWechatBlock = weChatBlock;
}

- (instancetype)initWithFrame:(CGRect)frame {
	self = [super initWithFrame:frame];
	if (self) {
		[self loadAllSubView];
	}
	return self;
}

- (void)loadAllSubView {
	[self addSubview:self.leftView];
	
	[self.leftView addSubviews:@[self.leftImageView,self.leftLabel,self.leftButton]];
	
	[self addSubview:self.rightView];
	[self.rightView addSubviews:@[self.rightImageView,self.rightLabel,self.rightButton]];
	
	[self.leftView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.equalTo(CGSizeMake((ScreenWidth - kQKFitModuleDecimal(16 + 21)) / 2, kQKFitModuleDecimal(42)));
		make.left.equalTo(self.mas_left).offset(kQKFitModuleDecimal(8.0));
		make.centerY.equalTo(self.mas_centerY);
	}];
	
	[self.leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.equalTo(CGSizeMake(kQKFitModuleDecimal(28), kQKFitModuleDecimal(28)));
		make.centerY.equalTo(self.mas_centerY);
		make.left.equalTo(self.leftView.mas_left).offset(kQKFitModuleDecimal(34));
	}];
	
	[self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(self.mas_centerY);
		make.left.equalTo(self.leftImageView.mas_right);
	}];
	
	[self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
		make.edges.equalTo(self.leftView);
	}];
	
	
	[self.rightView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.equalTo(CGSizeMake((ScreenWidth - kQKFitModuleDecimal(16 + 21)) / 2, kQKFitModuleDecimal(42)));
		make.centerY.equalTo(self.mas_centerY);
		make.right.equalTo(self.mas_right).offset(-kQKFitModuleDecimal(8.0));
	}];
	
	[self.rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
		make.size.equalTo(CGSizeMake(kQKFitModuleDecimal(28), kQKFitModuleDecimal(28)));
		make.left.equalTo(self.rightView.mas_left).offset(kQKFitModuleDecimal(34));
		make.centerY.equalTo(self.rightView.mas_centerY);
	}];
	
	[self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
		make.centerY.equalTo(self.mas_centerY);
		make.left.equalTo(self.rightImageView.mas_right);
	}];
	
	[self.rightButton mas_makeConstraints:^(MASConstraintMaker *make) {
		make.edges.equalTo(self.rightView);
	}];
}

- (void)clickShareQQbuttonAction {
	if (self.clickQQBlock) {
		self.clickQQBlock();
	}
}

- (void)clickShareWechatAction {
	if (self.clickWechatBlock) {
		self.clickWechatBlock();
	}
}

#pragma mark----- lazy init -----

- (UIButton *)leftButton {
	if (!_leftButton) {
		_leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
		[_leftButton addTarget:self action:@selector(clickShareQQbuttonAction) forControlEvents:UIControlEventTouchUpInside];
	}
	return _leftButton;
}

- (UIButton *)rightButton {
	if (!_rightButton) {
		_rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
		[_rightButton addTarget:self action:@selector(clickShareWechatAction) forControlEvents:UIControlEventTouchUpInside];
	}
	return _rightButton;
}

- (UIView *)leftView {
	if (!_leftView) {
		_leftView = [[UIView alloc] init];
		_leftView.backgroundColor = COLOR_WITH_HEX(0xFFC236);
		_leftView.layer.cornerRadius = kQKFitModuleDecimal(6.0);
		_leftView.layer.masksToBounds = YES;
	}
	return _leftView;
}

- (UIImageView *)leftImageView {
	if (!_leftImageView) {
		_leftImageView = [[UIImageView alloc] init];
		_leftImageView.image = [UIImage imageNamed:@"share_qq_pic"];
	}
	return _leftImageView;
}

- (UILabel *)leftLabel {
	if (!_leftLabel) {
		_leftLabel = [UILabel labelWithText:@"分享到QQ" font:[UIFont systemFontOfSize:kQKFitFont(16)] textColor:[UIColor whiteColor]];
	}
	return _leftLabel;
}

- (UIImageView *)rightImageView {
	if (!_rightImageView) {
		_rightImageView = [[UIImageView alloc] init];
		_rightImageView.image = [UIImage imageNamed:@"share_wechat_pic"];
	}
	return _rightImageView;
}

- (UILabel *)rightLabel {
	if (!_rightLabel) {
		_rightLabel = [UILabel labelWithText:@"分享到微信" font:[UIFont systemFontOfSize:kQKFitFont(16)] textColor:[UIColor whiteColor]];
	}
	return _rightLabel;
}

- (UIView *)rightView {
	if (!_rightView) {
		_rightView = [[UIView alloc] init];
		_rightView.backgroundColor = COLOR_WITH_HEX(0xFFC236);
		_rightView.layer.cornerRadius = kQKFitModuleDecimal(6.0);
		_rightView.layer.masksToBounds = YES;
	}
	return _rightView;
}

@end
